export const USER = 'user'; // 消息

export default {
  state: {
    'friend_list': []
  },
  getters: {
    friend_list: state => {
      return state.friend_list;
    }
  },
  mutations: {
    [USER](state, new_friend) {
      //处理不同type的数据
      //{'fd':'','name'}
      var length = state.friend_list.length
      if(length == 0){
        state.friend_list.push(new_friend)
      }else{
        //若无重复则插入
        state.friend_list.forEach(
          function(item,index){
             if(item.fd == new_friend.fd){
               if(item != new_friend){
                 state.friend_list.splice(index, 1);
                 state.friend_list.push(new_friend)
                 return false
               }
             }
             if(length == index){
               state.friend_list.push(new_friend)
             }
           }
         )
      }


    }
  },
  actions: {
    [USER]({ commit }, friend_list) {
      commit(USER, friend_list);
    }
  },
};
